Skip to content

Added DICOM C-GET, C-MOVE and DICOMWeb support#6

Open
ThalesMMS wants to merge 50 commits intoOPALE-dev:masterfrom
ThalesMMS:pr/dcm-swift_new
Open

Added DICOM C-GET, C-MOVE and DICOMWeb support#6
ThalesMMS wants to merge 50 commits intoOPALE-dev:masterfrom
ThalesMMS:pr/dcm-swift_new

Conversation

@ThalesMMS
Copy link

This pull request introduces support for C-MOVE and C-GET DIMSE services, and adds a new module for DICOMweb WADO-RS communication. These changes extend the library's networking capabilities to cover additional query/retrieve workflows.

Summary of Additions:

  1. New DIMSE Services:

    • C-MOVE SCU: Enables instructing a remote AE to initiate a C-STORE sub-operation to a specified destination.

    • C-GET SCU: Enables retrieving DICOM objects directly over the request association via C-STORE sub-operations.

  2. DICOMweb (WADO-RS) Module:

    • A new networking stack for DICOMweb has been added, using URLSession and Swift's async/await.

    • This allows for retrieving DICOM objects (studies, series, instances) from RESTful DICOMweb servers.


Implementation Details:

1. C-MOVE and C-GET Implementation

  • New ServiceClassUser classes CMoveSCU.swift and CGetSCU.swift have been added to manage the client-side logic.

  • The corresponding DIMSE messages (CMoveRQ/RSP, CGetRQ/RSP) are now implemented, including handling for sub-operation counters.

  • New command-line executables, DcmMove and DcmGet, have been added for direct use and testing of these services.

2. DICOMweb (WADO-RS) Implementation

The new DICOMweb module is structured as follows:

  • DICOMWebClient.swift: A base client for handling HTTP requests and authentication (Basic, Bearer Token).

  • MultipartParser.swift: A new utility to parse multipart/related responses, which is necessary for WADO-RS. It correctly identifies boundaries and extracts each DICOM part from the response body.

  • WADOClient.swift: Implements the WADO-RS specification, providing high-level methods to retrieve studies, series, and instances. It uses the MultipartParser to decode the server's response into DicomFile objects.

  • DICOMWebService.swift: A facade that provides a simplified API for using the DICOMweb services.


How to Test:

Testing DIMSE Services (C-MOVE / C-GET)

Requires a PACS that supports the Query/Retrieve Service Class.

C-MOVE Example:

    # Request a PACS to move a study to the destination AET "MY_WORKSTATION"
    swift run DcmMove -l STUDY -u "[Study Instance UID]" -d "MY_WORKSTATION" PACS_AE pacs.server.com 104

C-GET Example:

    # Retrieve a series and save the files to the "./received" directory
    swift run DcmGet -l SERIES -u "[Series Instance UID]" --output "./received" PACS_AE pacs.server.com 104

Testing DICOMweb (WADO-RS)

Requires a DICOMweb-enabled server (e.g., Orthanc, dcm4chee).

Example Swift Code:

    import DcmSwift
    import Foundation
    
    guard let baseURL = URL(string: "https://your-server.com/dicom-web") else { return }
    let service = DICOMWebService(baseURL: baseURL)
    
    // Optional: Add authentication
    // service.setAuthentication(.basic(username: "user", password: "password"))
    
    let studyUID = "1.2.840.113619.2.55.3.427103571.974.1252332153.511"
    
    Task {
        do {
            print("Retrieving study: \(studyUID)...")
            let dicomFiles = try await service.downloadStudy(studyUID)
            print("Successfully retrieved \(dicomFiles.count) instances.")
        } catch {
            print("Error retrieving study: \(error.localizedDescription)")
        }
    }
RunLoop.main.run(until: Date(timeIntervalSinceNow: 30))

Fixed issue with DcmSwift handing 12-bit data. Refactors DicomImage to provide a unified image(forFrame:wwl:inverted:) method for both macOS and iOS, supporting window/level adjustment and inversion for monochrome images. Adds a new renderFrame method for accurate grayscale rendering, handles both compressed and uncompressed images, and improves code clarity and maintainability. Also updates PhotometricInterpretation to be a String-backed enum.
@ThalesMMS ThalesMMS closed this Sep 7, 2025
@ThalesMMS ThalesMMS reopened this Sep 7, 2025
…-and-add-tests

feat: expose ROI measurement service
…nc-support

Add asynchronous DicomTool utilities
…r-methods

Add window level calculator with modality presets and conversions
…arge-images

Add concurrent 16-bit image processing fallback
…use-for-images

feat: reuse drawing context and cache processed image
…functions

Optimize pixel processing and translate comments
Introduces OPTIMIZATION_REVIEW.md summarizing integrated and missing optimizations in DcmSwift. Refactors DicomTool.swift to remove dependency on DicomServiceProtocol, implements direct DICOM decoding and display logic, improves window/level handling, and adds utility methods for pixel data extraction and validation.
Replaces DCMImgView with DicomPixelView and migrates all image rendering logic into DcmSwift/Graphics, introducing Metal-based GPU acceleration (MetalAccelerator, MetalShaders, Shaders.metal). Removes legacy References files, updates documentation and usage examples, and adds PixelService. Updates networking and data handling for improved performance and reliability. Package.swift now includes Metal shader resources.
…du-dicom

Ensure C-FIND PDVs and text padding follow DICOM
…tion-for-performance

Optimize Metal window-level pipeline for better parallelism
Refactored C-FIND request handling to send command and dataset in separate PDUs, and updated response parsing for fragmented datasets. Fixed AE title padding to use spaces instead of nulls. Enhanced UserInfo PDU construction to include Implementation UID and Version. Added test scripts for C-FIND and C-ECHO operations.
…ations-implementation

Fix dataset flags and group length for C-MOVE and C-GET RQ
…tion-for-performance-ibb8h2

Optimize Metal window-level pipeline for better parallelism
…coder-and-dcmimgview-056qdh

Use memory-mapped Data for faster input streams
…es-and-progress

Stream pixel frames and reuse Metal buffers for GPU windowing
…currency

Refactor windowing with Swift concurrency
…r-mtlbuffers

feat: add Metal buffer cache and RGB support
…s-using-vdsp

Optimize window/level with vDSP
…ata-reading

feat: stream DICOM pixel data fragments
Replaces async/await task groups with DispatchQueue.concurrentPerform for concurrent window/level and LUT application, improving performance and compatibility. Updates DicomPixelView to use background tasks for 8-bit window/level processing, with fallback for older OS versions. Refines Accelerate usage for type conversion, and updates Metal shader and dispatch logic to support variable output components and more robust threadgroup handling.
Refactors CFindRQ to send both the command and dataset together in a single P-DATA-TF PDU, updating CommandDataSetType handling per DICOM PS 3.7. Adds a unit test to verify correct PDV packing and CommandDataSetType values.
Enhances DIMSE C-GET and C-STORE handling to support correct PDV packing, multi-fragment C-STORE sub-operations, and robust file saving with proper Part-10 meta headers. Adds support for more DICOM modalities, improves memory management for large files, and fixes presentation context selection for responses. Includes new tests for C-GET DIMSE packing and DataTF status handling, and improves QIDOClient modality query logic.
The README has been rewritten to provide a comprehensive overview of DcmSwift, including GPU-accelerated image processing, full networking (DIMSE and DICOMweb), performance optimizations, and production readiness. It now details key features, architecture, benchmarks, main APIs, integration steps, and command-line tool usage, offering clearer guidance for developers and highlighting the library's capabilities and requirements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant